package com.vip.jwt.service.impl;

import com.vip.jwt.common.utils.menu.Menu;
import com.vip.jwt.common.utils.menu.MenuTreeUtil;
import com.vip.jwt.entity.SystemMenu;
import com.vip.jwt.mapper.SystemMenuMapper;
import com.vip.jwt.service.SystemMenuService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 菜单表 服务实现类
 * </p>
 *
 * @author vip
 * @since 2020-06-06
 */
@Service
public class SystemMenuServiceImpl extends ServiceImpl<SystemMenuMapper, SystemMenu> implements SystemMenuService {

    @Resource
    private SystemMenuMapper systemMenuMapper;

    @Override
    public List<Menu> tree() {
        List<SystemMenu> menus = systemMenuMapper.selectList(null);
        List<Menu> menuList =  menus.stream().map(v->new Menu(v.getId(),v.getTitle(),v.getUrl(),v.getSort(),v.getIcon(),v.getParentId()))
                .collect(Collectors.toList());
        return new MenuTreeUtil(menuList).buildTree();
    }

}
